feat: add SessionInfo abstraction for external session ID tracking#2037
Open
edis-uipath wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat: add SessionInfo abstraction for external session ID tracking#2037edis-uipath wants to merge 1 commit intomodelcontextprotocol:mainfrom
edis-uipath wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
The transport previously owned session state directly via self.session_id, making it impossible for consumers to observe or persist session IDs (e.g. to debug state for playground mode). Introduce a SessionInfo base class with async get/set methods that the transport delegates to. Consumers can subclass SessionInfo to add side-effects like session id persistence, and pass it via the new session_info parameter on StreamableHTTPTransport and streamable_http_client. Key changes: - Add SessionInfo class with async get_session_id/set_session_id - Transport stores _session_info instead of session_id - _prepare_headers and _maybe_extract_session_id_from_response are now async - Remove unused session_id field from RequestContext - streamable_http_client accepts optional session_info parameter Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In some cases we need to save the session id or to restore an existing session id and to continue from it, in some cases we need to move a session across process boundary (for example debug or human in the loop scenarios).
The transport previously owned session state directly via
self.session_id, making it impossible for consumers to observe or persist session IDs externally (e.g. persisting to a debug state endpoint for playground/agent resume scenarios).This PR introduces a
SessionInfobase class with asyncget_session_id/set_session_idmethods that the transport delegates all session ID storage to. Consumers can subclassSessionInfoto add side-effects like HTTP persistence, and pass it via the newsession_infoparameter onStreamableHTTPTransportandstreamable_http_client.Key changes
SessionInfoclass — base class with async get/set methods; default implementation stores in a plain attribute (backwards compatible)_session_info— replaces directself.session_idusage_prepare_headersand_maybe_extract_session_id_from_responseare now async — to support subclasses that need I/O (e.g. loading from a remote store)session_idfield fromRequestContext— headers are built from_prepare_headers, not from the contextstreamable_http_clientaccepts optionalsession_infoparameter — passed through to the transport constructorget_session_idis now async — delegates toSessionInfo.get_session_id()Backwards compatibility
session_infois provided, a plainSessionInfo()is created internallyRequestContext.session_idfield was not used by any handler (headers come from_prepare_headers)Example usage
Track the session ID externally:
Resume an existing session (skip initialize):